using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Sedna.Core.Common.Objects.Navigation;
using Sedna.Core.Controls;
using Spring.Util;

namespace Sedna.Core.Controller.Configurations
{
    public class LocationEnterConfigurator : IDataGridInnerControlConfigurator
    {
        private IScopePathParser scopePathParser;
        
        private string vaultCodePath;
        private string vaultExcludePath;

        # region Properties

        public IScopePathParser ScopePathParser
        {
            set { scopePathParser = value; }
        }

        public string VaultCodePath
        {
            set { vaultCodePath = value; }
        }               
        
        public string VaultExcludePath
        {
            set { vaultExcludePath = value;}
        }
        
        # endregion


        public void Configure(Control control, IDataGridColumnConfiguration columnConfiguration, object dataRow,
                              IExecutionContext executionContext)
        {

            Enter enter = (Enter)control;

            string vaultCode = scopePathParser.Parse(dataRow, vaultCodePath).Value as string;
            string vaultExcludeId = scopePathParser.Parse(dataRow, vaultExcludePath).Value as string;

            if (!StringUtils.IsNullOrEmpty(vaultCode))
                enter.PopupButton.PopupParameters = "site.text=" + vaultCode;
            else
                if (!String.IsNullOrEmpty(vaultExcludePath))
                    enter.PopupButton.PopupParameters = "site.exclude=" + vaultExcludeId;
        }
    }
}
